#pragma once
#include "obj.h"
#include "ThreadControl.h"
#include <vector>
extern void ScriptDelay(long index, long time);
extern void UpdateAction(long index, CString msg);
class CWork
{
public:

	CWork(long index) : index{index},dm { g_info[index].dm }{

	};
	void UpdateActionEx(const TCHAR* format, ...) {
		va_list	args;
		va_start(args, format);
		int len = _vsctprintf(format, args);
		if (len > 0)
		{
			len += (1 + 2);
			PTCHAR buf = (PTCHAR)malloc(sizeof(TCHAR) * len);
			if (buf)
			{
				len = _vstprintf_s(buf, len, format, args);
				if (len > 0)
				{
					while (len && _istspace(buf[len - 1])) len--;
					buf[len++] = _T('\r');
					buf[len++] = _T('\n');
					buf[len] = 0;
					UpdateAction(index, buf);
				}
				free(buf);
			}
			va_end(args);
		}
	}
	void ScriptDelayEx(long time) {
		ScriptDelay(index, time);
	}
	~CWork()
	{
		if (dm != nullptr) {
			delete dm;
		}
	}
	dmsoft* dm;
	long index;
public:
	double DistanceMe(int x, int y);
	std::vector<CPoint> CalcBoss();
	bool KillLiveBoss();
	bool BossIsLive(int xx, int yy);
	bool OpenMap();
	void MoveToEx(int x, int y, int ofx, int ofy, long t);
	void MoveToEx(CPoint p, CPoint offp, long t);
	void MoveToEx(int x, int y, long t);
	void MoveToEx(CPoint p, long t);
	void MoveToR(CPoint p, long t);
	void MoveToR(CPoint p, int ofx, int ofy, long t);
	void MoveToR(int x, int y, long t);
	void MoveToR(CPoint p, CPoint offp, long t);
	void MoveToR(int x, int y, int ofx, int ofy, long t);

	int Pos(CString str, int i);

	CPoint PosEx(CString str);

	CPoint Close(int xx, int yy, int ww, int hh);
	CPoint Close();
	void CloseAll();

	bool IsPointDead(long t);

	bool checkStart(int x, int y, int w, int h, int t);

	bool checkStartKill();

	bool checkStartUseSkill();

	bool IsDisplayDeadEx();

	LONG Run(int xx, int yy, int rt);

	LONG RunEx(int xx, int yy, int rt);

	LONG Run(int xx, int yy);

	BOOL RunWeel(int xx, int yy);

	void StartKill();

	bool CheckMapOpen();

	bool CloseMap();

	bool BossKilled(int x, int y);

	void PickUp();

	void Times(int x);

	bool Check(CPoint p);

	bool Killing();

	bool KillingBoss();

	void LogEx(const TCHAR* format, ...);

	void StartAutoGj(long t);

	void DoIceBoss();

	void DoIceGj();

};

